package com.czk.durant.springframework.core.io;

import cn.hutool.core.lang.Assert;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * 通过 HTTP 的方式读取云服务的文件
 *
 * @Author:ChenZhangKun
 * @Date: 2021/6/21 9:32
 */
public class URLResource implements Resource {
    private final URL url;

    public URLResource(URL url) {
        Assert.notNull(url, "url不能为空");
        this.url = url;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        // 打开连接
        URLConnection connection = this.url.openConnection();
        InputStream inputStream = connection.getInputStream();
        return inputStream;
    }
}
